package com.qzdsoft.erpcloud.service.com.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.qzdsoft.erpcloud.domain.com.CustomerSupplierContacts;
import com.qzdsoft.erpcloud.domain.com.SupplierCustomer;
import com.qzdsoft.erpcloud.mapper.com.CustomerSupplierContactsMapper;
import com.qzdsoft.erpcloud.mapper.com.SupplierCustomerMapper;
import com.qzdsoft.erpcloud.service.com.CustomerSupplierService;
import com.qzdsoft.erpcloud.vo.com.SupplierCustomerInfo;
import com.qzdsoft.erpcloud.vo.com.SupplierCustomerQueryInfo;
import com.qzdsoft.erpcloud.vo.com.SupplierCustomerQueryParam;
import com.qzdsoft.vo.LayTableResponse;
import com.qzdsoft.vo.Response;
import com.qzdsoft.vo.ResultEnum;
import com.qzdsoft.vo.TypeInfo;

@Service
public class CustomerSupplierServiceImpl implements CustomerSupplierService
{

    @Autowired
    private CustomerSupplierContactsMapper customerSupplierContactsMapper;

    @Autowired
    private SupplierCustomerMapper supplierCustomerMapper;

    @Override
    public List<CustomerSupplierContacts> selectAll(String id)
    {
        CustomerSupplierContacts contacts = new CustomerSupplierContacts();
        contacts.setSupplierCustomerId(Integer.parseInt(id));
        return customerSupplierContactsMapper.select(contacts);
    }

    @Override
    public List<SupplierCustomer> selectBy(SupplierCustomerQueryInfo info)
    {
        PageHelper.startPage(info.getPage(), info.getLimit());
        return supplierCustomerMapper.selectByName(info.getCompanyid(), info.getType(), info.getName());
    }

    @Override
    public TypeInfo selectTaxInfo(Integer companyid, Integer customerSupplierid)
    {
        return supplierCustomerMapper.selectTaxInfo(companyid, customerSupplierid);
    }
    /**
     * 查询所有的供应商
     * @see com.qzdsoft.erpcloud.service.com.CustomerSupplierService#findAllSupplier()
     */
    @Override
    public List<SupplierCustomer> findAllSupplier()
    {
        return this.supplierCustomerMapper.findAllSupplier();
    }

	@Override
	public LayTableResponse selectData(SupplierCustomerQueryParam info) {
		PageHelper.startPage(info.getPage(), info.getLimit());
		List<SupplierCustomerInfo> data = supplierCustomerMapper.selectData(info.getCompanyId(),info.getName(),info.getType());
		return new LayTableResponse(data);
	}

	@Override
	public SupplierCustomer selectById(Integer id) {
		 return supplierCustomerMapper.selectByPrimaryKey(id);
	}

	 @Override
	    public Response del(Integer id) {
	        supplierCustomerMapper.deleteByPrimaryKey(id);
	        return new Response(ResultEnum.SUCCESS);
	    }
	

	 @Override
	    public Response edit(SupplierCustomer comSupplierCustomer) {
	        if(null != comSupplierCustomer.getId()){        //  编辑
	            int ui = supplierCustomerMapper.updateByPrimaryKeySelective(comSupplierCustomer);
//	            return new Response("编辑成功");
	            return Response.success("编辑成功");
	        } else {
	            comSupplierCustomer.setCtime(new Date());
	            supplierCustomerMapper.insert(comSupplierCustomer);
	            return Response.success("新增成功");
	        }
	    }

	@Override
	public SupplierCustomerInfo selectDetailById(Integer id) {
		SupplierCustomerInfo lists = supplierCustomerMapper.selectById(id);
		return lists;
	}
	 
	 
}
